import { fileURLToPath, URL } from 'node:url'

import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import VueDevTools from 'vite-plugin-vue-devtools'

const proxyDomain = "gtinlian.com:800";
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    VueDevTools(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    /** 代理配置 */
    proxy: {
      "/api" : {
        target: "http://"+proxyDomain,
        changeOrigin: true,
        timeout: 1000
      },
      /** websockify 远程桌面  */
      "/ws": {
        target: "ws://"+proxyDomain,
        changeOrigin: true,
        rewrite: (path:any) => path.replace(/^\/ws\//, '')
      },
      /** 安卓scrcpy 远程桌面 */
      '/scrcpy': {
        target: "ws://"+proxyDomain,
        changeOrigin: true,
      },
      '//scrcpy': {
        target: "ws://"+proxyDomain,
        changeOrigin: true,
      },
    }
  },
  build: {
    outDir: "../nginx/html"
  }
})
